package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/5 15:18
 * @description
 */
public class Code148 {
    private List<Integer> list = new ArrayList<>();

    public ListNode sortList(ListNode head) {
        getList(head);
        Collections.sort(list);
        setList(head, 0);
        return head;
    }

    private void getList(ListNode node) {
        if (node != null) {
            list.add(node.val);
            getList(node.next);
        }
    }

    private void setList(ListNode node,int num){
        if (node != null) {
            node.val = list.get(num);
            setList(node.next, num += 1);
        }
    }
}
